package cn.xchats.demo.core.service;

import cn.xchats.demo.core.api.UserApi;
import cn.xchats.demo.core.dto.UserDto;
import cn.xchats.rpc.common.annotation.RpcService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/*
 *
 *@author teddy
 *@date 2018/7/4
 */
@RpcService(RpcInterface = UserApi.class)
public class UserApiService implements UserApi {

    private static final List<UserDto> userList = new ArrayList<>();

    @Override
    public boolean createUser(UserDto user) {
        if (null != user)
            userList.add(user);
        else
            System.out.println("user is null");
        return false;
    }

    @Override
    public UserDto getUser(String id) {
        if (null == id)
            return null;
        for (int i = 0; i < userList.size(); i++) {
            UserDto userDto = userList.get(i);
            if (userDto.getId().equals(id))
                return userDto;
        }
        return null;
    }

    @Override
    public List<UserDto> listUser() {
        return userList;
    }
}
